// This kernel fetches data from global memory to kernel and 
// then directly stores them back to global memory
// Different accessing patterns are compared to the influences on bandwidth
// 2020.11.17 by wangdong@bjtu.edu.cn

#include "ap_axi_sdata.h"
#include "ap_int.h"
#include "hls_stream.h"

#define VEC_SIZE    16

typedef ap_uint<VEC_SIZE*32> data_vec;
//typedef struct {
//   ap_uint<32> data[VEC_SIZE];
//} data_vec;

typedef ap_axiu<VEC_SIZE*32,0,0,0> k2k_data;

extern "C" {
void DataStore(
				data_vec *B_out,       //HBM[1]
				data_vec *D_out,       //HBM[3]
				const unsigned int data_num,
				hls::stream<k2k_data> &stream_in_0,
				hls::stream<k2k_data> &stream_in_1
				)
{
#pragma HLS INTERFACE m_axi port = B_out offset = slave bundle = gmem2 // group-0
#pragma HLS INTERFACE m_axi port = D_out offset = slave bundle = gmem3 // group-1
#pragma HLS INTERFACE axis port = stream_in_0 depth = 16
#pragma HLS INTERFACE axis port = stream_in_1 depth = 16

	k2k_data tmp;

	for(unsigned int i=0; i<data_num; i++){
		tmp = stream_in_0.read();
		B_out[i] = tmp.data;
		tmp = stream_in_1.read();
		D_out[i] = tmp.data;
    }

}
}